package day14.Volatile;

public class Lian01 {
    public static void main(String[] args) {
        boy b1 = new boy();
        b1.setName("小王");
        b1.start();
        girl g1 = new girl();
        g1.setName("小丽");
        g1.start();
    }
}

class Money {
    public static volatile int money = 100000;
    public static Object lock=new Object();
}

class boy extends Thread {
    @Override
    public void run() {
        synchronized (Money.lock) {
            try {
                Thread.sleep(100);
                Money.money = 90000;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class girl extends Thread {
    @Override
    public void run() {
        while (true){
            synchronized (Money.lock){
                if (Money.money!=100000){
                    System.out.println("结婚基金不是十万了");
                    break;
                }
            }
        }
    }
}